package com.heima.user.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dtos.AuthDto;
import com.heima.model.user.pojos.UserRealname;
import com.heima.user.service.UserRealnameService;
import com.heima.user.mapper.UserRealnameMapper;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class UserRealnameServiceImpl extends ServiceImpl<UserRealnameMapper, UserRealname>
    implements UserRealnameService{

    @Override
    public PageResponseResult loadListByStatus(AuthDto dto) {
        //参数为空
        if(dto==null){
            return (PageResponseResult) ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //检查参数
        dto.checkParam();
        QueryWrapper<UserRealname> queryWrapper = new QueryWrapper();
        if(dto.getStatus()!=null){
            queryWrapper.lambda().eq(UserRealname::getStatus,dto.getStatus());
        }
        IPage pageParam = new Page(dto.getPage(),dto.getSize());
        IPage page = page(pageParam, queryWrapper);
        PageResponseResult responseResult = new PageResponseResult(dto.getPage(),dto.getSize(),(int)page.getTotal());
        responseResult.setCode(0);
        responseResult.setData(page.getRecords());
        return responseResult;
    }
}




